extends ../mixins/_layout

block content
    body
        #wrapper(style='min-height:660px;')

            #login(autocomplete="on", onsubmit='return false;')
                h2.signTitle 登录账号
                form#signBox
                    p.explain 请输入账号或邮箱
                    .inputBox
                        input#account(name="account", type="text")
                    p.explain 请输入您的密码
                    .inputBox
                        input#password(name="password", type="password")
                    button#signBtn.signBtn(type='submit') 登录

            include ../mixins/_footer
            +footer

        script(src="/js/base.js")
        script.
            window.addEventListener('DOMContentLoaded',function(){
                var form=$('login'), ac=$('account'), pw=$('password'), signBtn=$('signBtn');
                function formSubmit(){
                    if(ac.value==""){
                        return alert('请先输入账号!');
                    }
                    if(pw.value==""){
                        return alert('请输入密码!');
                    }
                    $$.ajax({
                        'type':"POST",
                        'url':'/login',
                        'data':{
                            'account' : ac.value,
                            'password' : pw.value  //实际开发中请使用 md5 进行加密
                        },
                        'success':function(data){
                            var _data=JSON.parse(data);
                            if(_data.status==1){
                                window.location.href='/admin';
                            }else{
                                alert(_data.msg);
                            }
                        }
                    });
                };
                signBtn.onclick=function(){
                    formSubmit();
                };
                document.onkeydown=function(e){
                    var keynum,ev = e||window.event;
                    if(window.event){
                        keynum=e.keyCode
                    }else if(e.which){
                        keynum = e.which
                    }
                    if(keynum==13){
                        formSubmit();
                    }
                }
            });
